package routePlanner.database;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Logger;

public class RouteDbTablesCreator {
	private final static Logger LOGGER = Logger.getLogger(RouteDbTablesCreator.class.getName());
	private static final String ATRACTION_SQL = "CREATE TABLE IF NOT EXISTS atractions (id_atraction INTEGER PRIMARY KEY AUTOINCREMENT, atraction_name varchar(255), description varchar(255), rank double, atractionType varchar(255))";
	private static final String CITY_SQL = "CREATE TABLE IF NOT EXISTS cities (id_city INTEGER PRIMARY KEY AUTOINCREMENT, city_name varchar(255), id_atraction int, latitude int, longitude int, altitude int)";
	private static final String VEHICLE_SQL = "CREATE TABLE IF NOT EXISTS vehicles (id_vehicle INTEGER PRIMARY KEY AUTOINCREMENT, vehicle_name varchar(255), km_cost double)";
	private static final String CITY_CONNECTIONS_SQL = "CREATE TABLE IF NOT EXISTS connections (id_connection INTEGER PRIMARY KEY AUTOINCREMENT, start_City int, end_city int, vehicle_id int, avg_speed double)";
	private RouteDatabaseCreator dbCreator;
	
	public RouteDbTablesCreator() {
		dbCreator = new RouteDatabaseCreator();
	}

	public void createTables() {
		try {
			Connection connection = dbCreator.getConnection();
			connection.createStatement().execute(ATRACTION_SQL);
			connection.createStatement().execute(CITY_SQL);
			connection.createStatement().execute(VEHICLE_SQL);
			connection.createStatement().execute(CITY_CONNECTIONS_SQL);
			connection.close();
		} catch (SQLException e) {
			LOGGER.info("CANNOT CREATE TABLES IN DATABASE");
			e.printStackTrace();
		}
	}

}
